/*
 * assembler.c
 *
 *  Created on: 30 Apr 2011
 *      Author: franz08
 */
#include "assembler.h"
#include <string.h>
ll *first2 = NULL;
ll *alloc = NULL;
ll *dealloc = NULL;
int runs2 = 0;
int temps = 0;
int regid2;
ll *makeASSEMBLER(ll *front){
	asc *asc;
	if(runs2==0){
		first2 = front;
	}
	runs2++;
	regid2 = 0;
	if(front->asc != NULL){
		asc = front->asc;
		if(asc->kind == ALLOC){
			alloc = front;
			while(asc->kind!= DEALLOC){
				front = front->next;
				asc = front->asc;
				if(asc->kind==MOV_CONST){
					if(asc->par.arguments_const.second->id>regid2){
						temps++;
						regid2 = asc->par.arguments_const.second->id;
					}
				}
			}
			dealloc = front;
			alloc->asc->par.arguments_const.first = 0-(temps*4);
			dealloc->asc->par.arguments_const.first = (temps*4);
			fprintf(stderr,"TEMPORARIES: %d\n",temps*4);
		}
	}
	if(front->next != NULL){
		makeASSEMBLER(front->next);
	}else{
		fprintf(stderr,"Done generating assembler\n");
	}
	return first2;
}
